﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ExtraOpdrachten
{
    public partial class Opdracht6 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnCalculateAge_Click(object sender, EventArgs e)
        {
            DateTime birthDate;
            if(!DateTime.TryParse(txtDay.Text + "-" + txtMonth.Text
                + "-" + txtYear.Text, out birthDate))
            {
                lblResult.Text = "Dit is geen geldige datum. ";
                return;
            }
            int age = DateTime.Now.Year - birthDate.Year;
            // Verlaag de leeftijd met 1 omdat de verjardag nog niet is geweest
            if(DateTime.Now.DayOfYear < birthDate.DayOfYear)
            {
                age--;
            }
            if (age < 18)
            {
                lblResult.Text = "Jouw leeftijd is " + age.ToString() + " jaar.";
            }
            else
            {
                lblResult.Text = "Uw leeftijd is " + age.ToString() + " jaar.";
            }

        }
    }
}